<html>
<head>
    <title>链表反转</title>
</head>
<body>
    <h3>Demo</h3>
    <pre>
        LinkNode: 
        function LinkNode(node) {
            this.val = node.val || null;
            this.next = node.next || null;
        }

        MockData: 
        linkList = {
            val: '1',
            next: {
                val: '2',
                next: {
                    val: '3',
                    next: {
                        val: '4',
                        next: {
                            val: '5'
                        }
                    }
                }
            }
        };

        反转结果：
        {
            val: '5',
            next: {
                val: '4',
                next: {
                    val: '3',
                    next: {
                        val: '2',
                        next: {
                            val: '1'
                        }
                    }
                }
            }
        }
    </pre>

    <script>
        var linkList = {
            val: '1',
            next: {
                val: '2',
                next: {
                    val: '3',
                    next: {
                        val: '4',
                        next: {
                            val: '5'
                        }
                    }
                }
            }
        };
        
        function reverseList(head) {
            let prev = null;
            let cur = head;
            while (cur) {
                const nextNode = cur.next;
                cur.next = prev;
                prev = cur;
                cur = nextNode;
            }
            console.log('reverseList:', prev);
            return prev;
        }
        reverseList(linkList);
    </script>
</body>
</html>